def ie(n):
  if n <= 1:
    return False
  for i in range(2, int(n*0.5) + 1):
    if n % i == 0:
      return False
  return True

def ce(nu):
  le = nu - 1
  he = nu + 1
  while True:
    if ie(le):
      return le
    if ie(he):
      return he
    le -= 1
    he += 1

def cer(w):
  dp = {"zero": 0, "one": 1, "two": 2, "three": 3, "four": 4, 
              "five": 5, "six": 6, "seven": 7, "eight": 8, "nine": 9}
  if len(w) != 3:
    return None
  n = 100 * dp[w[0]] + 10 * dp[w[1]] + dp[w[2]]
  return n

i = input().split()
n = cer(i)

if n is None or n < 100 or n > 999:
  print("Wrong input")
else:
  print(ce(n))
